<?php $this->placeholder('toolBar')->captureStart();?>
<input type="button" class="button" onclick="approveSelected();" value="Принять" />
<input type="button" class="button" onclick="deleteSelected();" value="Удалить" />
<?php $this->placeholder('toolBar')->captureEnd() ?>


<script>
function getSelectIds()
{
	var ids = [];
	$(".ids").filter(':checked').each(function (){
			ids.push($(this).val());
		});

	return ids;
}

function deleteSelected()
{
	if ( !confirm('Удалить?') ) return;

	blockUI('Идет удаление...');
	
	var ids = getSelectIds();
	$.post(url('guest-book/edit/remove'), {'ids':ids}, function(){ 
		unBlockUI();
		$(ids).each(function (key, value){
				$("#" + value ).parent().parent().fadeOut();
			});
		});
}


function approveSelected()
{
	if ( !confirm('Одобрить выбранные?') ) return;

	blockUI('Обновление');
	
	var ids = getSelectIds();
	$.post(url('guest-book/edit/approve'), {'ids':ids}, function(){ 
		unBlockUI();
		$(ids).each(function (key, value){
				$("#" + value ).parent().parent().css('background', 'none');
				$("#" + value ).removeAttr('checked');
			});
		});
}
</script>

<table style="width: 70%" class="niceTable">
  <tr>
  	<th width="5">#</th>
  	<th>Текст</th>
  	<th width="20">Дата</th>
    <th width="30">Email</th>
  </tr>
  <?php 
foreach($this->News as $Item)
{
    $color = "";
    if  (!$Item['approved'])
    $color = "background-color:#E77471;";
?>

  <tr style="<?=$color ?>">
  	<td><input type="checkbox" class="ids" name="ids[]" id="<?=$Item['ID'] ?>" value="<?=$Item['ID'] ?>"/></td>
  	<td><a href="#" onclick="return false" class="explanation" original-title="<?php echo $this->escape($Item['text']) ?>"><?= $this->escape( mb_substr($Item['text'], 0, 150) ) ?></a></td>
  	<td><?php echo mb_substr($Item['date'],0,mb_strpos($Item['date'],' ')) ?></td>
    <td><?php echo $Item['email'] ?></td>
  </tr>
  
<?php 
}
?>
</table>

<script>
$(".explanation").tipsy({delayIn: 500, delayOut: 1000,gravity: 'w'});
</script>

          
